let industrialMapData = JSON.parse(
  JSON.stringify(require('../../../public/restfulData/industrialMap.json'))
)

//将对象中文键转为英文
function toEnKeys(data, keyMap) {
  return data.map((item) => {
    let obj = {}
    for (let prop in item) {
      if (keyMap.hasOwnProperty(prop)) {
        obj[keyMap[prop]] = item[prop]
      }
    }
    return obj
  })
}

function convertCarList(data, target) {
  let keyMap = {
    类型: 'name',
    id: 'key',
    公司列表: 'company'
  }
  let chartData = toEnKeys(data, keyMap)
  chartData.forEach((item) => {
    item.company = JSON.parse(
      item.company.replace(/\ +/g, '').replace(/[\r\n]/g, '')
    )
  })
  target.carList = chartData
}

function convertIndustrialMapJson(data) {
  convertCarList(data['下游'], industrialMapData)
  return industrialMapData
}
export default convertIndustrialMapJson
